package com.sumainfor.pc.market.controller.rentadviser;

import com.sumainfor.common.util.DateUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.RdHousingConService;
import com.sumainfor.pc.market.service.RdPactService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 租客端合同相关
 */
@RestController
@RequestMapping("/tenant/key/rentadviser/RdWxPact")
public class RdWxPactController implements Serializable {
    Logger log = LoggerFactory.getLogger(RdWxPactController.class);// 日志
    @Autowired
    private RdPactService rdPactService;
    @Autowired
    private RdHousingConService rdHousingConService;

    /**
     * 租客续签合同
     * @param params
     * @return
     */
    @PostMapping("/addRerentPact")
    public JsonResult addRerentPact(@RequestBody Map<String, Object> params) {
        if(MapUtils.getInteger(params,"SenSend")>0){
            try {
                SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd");
                String EndTimeOne = MapUtils.getString(params,"EndTime");
                Date dateOne = a.parse(EndTimeOne);
                Date dateTwo = DateUtils.addDateMonths(dateOne,MapUtils.getInteger(params,"SenSend"));
                String zz = a.format(dateTwo);
                params.put("EndTime",zz);
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
        return rdPactService.addRerentPact(params);
    }

    /**
     * 租客端协助开门查询手机号是否该租客的室友
     */
    @PostMapping("/getRdPactTenPhoneCount")
    public JsonResult getRdPactTenPhoneCount(@RequestBody Map<String, Object> params) {
        return rdPactService.getRdPactTenPhoneCount(params);
    }

    /**
     * 协助开门 查询当前租客所签房源列表
     */
    @GetMapping("/getRdInteHouList")
    public JsonResult getRdInteHouList(@RequestParam Map<String, Object> params) {
        return rdPactService.getRdInteHouList(params);
    }

    /**
     * 租客端协助开门查询房源的房间配置
     */
    @PostMapping("/getRdInteHouConInfoList")
    public JsonResult getRdInteHouConInfoList(@RequestBody Map<String, Object> params) {
        return rdHousingConService.getRdInteHouConInfoList(params);
    }

    /**
     * 申请临时密码 查询该租客的房源信息列表
     */
    @GetMapping("/getRdTemInteHouConList")
    public JsonResult getRdTemInteHouConList(@RequestParam Map<String, Object> params) {
        return rdPactService.getRdTemInteHouConList(params);
    }

    /**
     * 智能设备充值 查询租客所租的智能设备房间
     */
    @GetMapping("/getRdInteDeviceHouConList")
    public JsonResult getRdInteDeviceHouConList(@RequestParam Map<String, Object> params) {
        return rdPactService.getRdInteDeviceHouConList(params);
    }

    /**
     * 智能设备充值 查询租客所租的房子智能设备余额的和
     */
    @GetMapping("/getRdCensusHouConList")
    public JsonResult getRdCensusHouConList(@RequestParam Map<String, Object> params) {
        return rdPactService.getRdCensusHouConList(params);
    }

    /**
     * 租客端续签的时候查询房源是否发起过续签
     */
    @GetMapping("/getRdRenPactData")
    public JsonResult getRdRenPactData(@RequestParam Map<String, Object> params) {
        return rdPactService.getRdRenPactData(params);
    }

}
